document.addEventListener('DOMContentLoaded', () => {
  // 初始化Socket.IO连接
  const socket = io('http://192.168.123.18:6002', {
      reconnection: true,
      reconnectionDelay: 1000,
      reconnectionAttempts: Infinity
  });
  
  // 初始化导航2D可视化
  const nav2d = new Nav2D('nav-canvas', socket);
  
  // 初始化控制面板
  const controlPanel = new ControlPanel(socket, nav2d);
  
  // 初始化键盘控制
  const keyboardControl = new KeyboardController(socket);
  
  // 初始化状态监视器
  const statusMonitor = new StatusMonitor(socket);
  
  // 初始化地图工具栏
  const mapTools = new MapTools(nav2d);
  
  // 系统状态检查
  checkSystemStatus(socket);
});

/**
* 系统状态检查
*/
function checkSystemStatus(socket) {
  const statusElement = document.getElementById('connection-status');
  
  socket.on('connect', () => {
      statusElement.textContent = 'Connected';
      statusElement.className = 'status-connected';
  });
  
  socket.on('disconnect', () => {
      statusElement.textContent = 'Disconnected';
      statusElement.className = 'status-disconnected';
  });
  
  socket.on('connect_error', () => {
      statusElement.textContent = 'Connection Error';
      statusElement.className = 'status-error';
  });
  
  // 请求初始数据
  socket.emit('request_initial_data');
}